define(['jquery', 'bootstrap','backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'Article/index',
                    add_url: 'Article/add',
                    edit_url: 'Article/edit',
                    del_url: 'Article/del',
                    multi_url: 'Article/multi',
                    import_url: 'Article/import_file',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                search: true,//id搜索
                commonSearch: true,//条件搜索
                pagination: true,//分页
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'category_id', title: __('CategoryName')},
                        {field: 'thumb', title: __('Thumb'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'title', title: __('Title')},
                        {field: 'author', title: __('Author')},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'isding', title: __('IsDing')},
                        {field: 'isindex', title: __('Isindex')},
                        {field: 'clicks', title: __('Clicks')},
                        {field: 'isrecommend', title: __('Isrecommend')},
                        {field: 'sort', title: __('Sort')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});